package com.zjw.zy.componse.demo.viewmodel

import android.util.Log
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import com.zjw.zy.componse.demo.base.BaseViewModel
import com.zjw.zy.componse.demo.bean.User
import com.zjw.zy.componse.demo.ext.launchInIo
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2023/2/16 14:56
 * @description：
 */
class LoginViewModel : BaseViewModel() {

    /**
     * 登录状态
     * */
    private val mLoginStatus = MutableSharedFlow<Boolean>()
    val loginStatus: SharedFlow<Boolean> by this::mLoginStatus

    /**
     * compose 提供的状态管理
     * */
    val loginStatus2: State<Boolean> = mutableStateOf(false)


    fun requestLogin(user: User) {
        launchInIo {
            //simple judge
            Log.d("test", "requestLogin: $user")
            //mLoginStatus.emit(user.username == "zjw" && user.password == "123")
            mLoginStatus.emit(true)
        }
    }
}